<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <span>后台管理系统</span>
      </div>
      <div>
        <span>{{user}}</span>
        <span @click="dialogVisible = true" class="quit">退出</span>
        <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before="handleClose">
          <span>亲~~确定退出吗？</span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="quit">确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <!-- <div>
        <span>{{user}}</span>
        <span>退出</span>
      </div>-->
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="'20rem'">
        <el-menu
          background-color="#373a6e"
          text-color="#fff"
          active-text-color="#fff"
          unique-opened
          :router="true"
          :default-active="activePath"
        >
          <template v-for="item in listRouter">
            <!--   -->
            <el-submenu
              v-if="item.id == yijiqx.filter(a=>{return a==item.id})"
              :key="item.id"
              :index="item.id+''"
            >
              <!-- 一级菜单的模板区域 -->
              <template slot="title">
                <!-- 文本 -->
                <img class="img1" :src="item.img" alt />
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级菜单 -->
              <template v-for="subItem in item.children">
                <!--  -->
                <el-menu-item
                  v-if="subItem.id == erjiqx.filter(a=>{return a==subItem.id})"
                  v-show="erqxshow"
                  :index="'/'+subItem.path"
                  :key="subItem.id"
                  @click="saveNavState('/' + subItem.path)"
                >
                  <template slot="title">
                    <!-- 文本 -->
                    <span class="wenben">{{subItem.authName}}</span>
                  </template>
                </el-menu-item>
              </template>
            </el-submenu>
          </template>
        </el-menu>
      </el-aside>
      <!-- 右侧 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  props: {
  },
  data () {
    return {
      // 所有权限
      Alluserjurisdiction: [],
      yiqxshow: true,
      erqxshow: true,
      dialogVisible: false,
      user: [],
      yijiqx: [],
      erjiqx: [],
      nUid: [],
      listRouter: [
        {
          id: 9, img: require('./img/值班表.png'), authName: '值班表',
          children: [{
            id: 10, authName: '值班表', path: 'users'
          }]
        },
        {
          id: 1, img: require('./img/图片管理.png'), authName: '图片管理',
          children: [
            { id: 11, authName: '设置轮播图', path: 'roles' },
            { id: 12, authName: '设置中心图', path: 'rights' },
          ]
        },
        {
          id: 2, img: require('./img/通讯录管理.png'), authName: '通讯录管理',
          children: [{
            id: 13, authName: '通讯录管理', path: 'adds'
          }]
        },
        {
          id: 3, img: require('./img/新闻管理.png'), authName: '新闻管理',
          children: [{
            id: 14, authName: '新闻管理', path: 'xinwen'
          },
          {
            id: 15, authName: '新闻类别管理', path: 'wer'
          }]
        },
        {
          id: 4, img: require('./img/人员管理.png'), authName: '人员管理',
          children: [
            { id: 16, authName: '单位管理', path: 'danwei' },
            { id: 17, authName: '人员管理', path: 'renyuan' }]
        },
        {
          id: 5, img: require('./img/链接.png'), authName: '链接管理',
          children: [
            { id: 18, authName: '查询链接设置', path: 'chaxun' },
            { id: 19, authName: '平台链接设置', path: 'pingtai' },
            { id: 20, authName: '专题专栏链接设置', path: 'zhuanti' },
            { id: 21, authName: '警员风采设置', path: 'jingyuan' },
          ]
        },
        {
          id: 6, img: require('./img/收件箱.png'), authName: '收件箱',
          children: [
            { id: 22, authName: '收件箱', path: 'sjx' }
          ]
        },
        {
          id: 7, img: require('./img/设 置.png'), authName: '系统设置',
          children: [
            { id: 23, authName: '系统设置', path: 'xtsz' }
          ]
        }
      ],
      // 被激活的链接地址
      activePath: "",
    }
  },
  created () {
    this.Get_Alluserjurisdiction()
    this.activePath = window.sessionStorage.getItem("activePath");
    this.user = Cookies.get('username')

    console.log(this.nUid);
  },
  methods: {
    // 获取登录人员的权限
    async Get_Alluserjurisdiction () {
      this.nUid = Cookies.get('nUid')
      const { data: res } = await this.$http.get('/api/userjurisdiction/Get_Alluserjurisdiction', {
        params: {
          innUid: this.nUid
        }
      })
      // console.log(res);
      this.Alluserjurisdiction = res
      console.log(this.Alluserjurisdiction[0].PerIdlist);


      var arrqx = new Array()
      var arrqx = this.Alluserjurisdiction[0].PerIdlist
      console.log(arrqx);
      // var arrqx = "abc,abcd,aaa";
      var aArr = null;
      aArr = arrqx.split(",")
      console.log(aArr)
      for (let i = 0; i < aArr.length; i++) {
        // console.log(aArr[i]);
        if (aArr[i] <= 9) {
          this.yijiqx.push(aArr[i])
        } else {
          this.erjiqx.push(aArr[i])
        }
      }
      console.log(this.yijiqx);
      console.log(this.erjiqx);
    },
    saveNavState (activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
    handleClose (done) {
      this.$confirm('亲~确认退出吗？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    quit () {
      this.$router.push('lanhu_houtaidenglu')
    },
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  div:first-child {
    width: 320px;
    height: 1080px;
    background: #373a6e;
    box-shadow: 1px 0px 4px 0px rgba(59, 124, 255, 0.1);
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
      font-size: 24px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      line-height: 33px;
    }
  }
  div:nth-child(2) {
    font-size: 18px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #323232;
    span {
      margin: 0 58px;
    }
  }
}

.el-aside {
  background-color: #373a6e;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #f5f5f5;
}

.iconfont {
  margin-right: 10px;
}
.el-menu-item.is-active {
  background: #3b7cff !important;
  z-index: 1;
}
.wenben {
  z-index: 999;
}
.el-submenu__title * {
  height: 54px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-size: 18px;
}
.el-menu-item * {
  height: 54px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-size: 18px;
}
.img1 {
  width: 26px;
  height: 26px;
  margin-right: 24px;
}
.quit {
  cursor: pointer;
}
</style>
